import http from '@/utils/http';
import { baseUrl } from './commonApi'

const paths = {
    getHotCourse: `${baseUrl}/course/hot`,
    getCourse: `${baseUrl}/course`,
    getCourseDetail: `${baseUrl}/course/{id}`,
    getCourseChapter: `${baseUrl}/course/{id}/chapter`,
    getLessonChapter: `${baseUrl}/lesson/{id}/chapter`,
    getStudentCourseList: `${baseUrl}/course/mine/option`,
    getStudentCourseCollect: `${baseUrl}/course/collect`,
    getCourseComment: `${baseUrl}/course/{id}/comment`,
    getLessonStatisticsActivity: `${baseUrl}/lesson-statistics/activity`,
    commentLike: `${baseUrl}/course-comment/{id}/like`,
    commentCancelLike: `${baseUrl}/course-comment/{id}/cancel-like`,
    getCourseHoursResource: `${baseUrl}/course-hour/{id}/resource`,
    signInCourseResource: `${baseUrl}/course-resource/sign-in/{id}`,
    getSignInCourseResource: `${baseUrl}/course-resource/sign-in/{id}/result`,
    vote: `${baseUrl}/course-resource/vote/{id}`,
    getVoteDetail: `${baseUrl}/course-resource/vote/{id}`,
    getVoteResult: `${baseUrl}/course-resource/vote/{id}/result`,
    cancelCourseCollect: `${baseUrl}/course/{id}/cancel-collect`,
    joinStatus: `${baseUrl}/course/join-status`,
    collectCourse: `${baseUrl}/course/{id}/collect`,
    cancelCollectCourse: `${baseUrl}/course/{id}/cancel-collect`,
    commentCourse: `${baseUrl}/course/{id}/comment`,
    getLessionOption: `${baseUrl}/lesson/option`,
    getResourceDetail: `${baseUrl}/course-resource/resource/{id}`,
    updateCourseActityStatus: `${baseUrl}/course-resource/{id}/learn`,
    getCourseMineNote: `${baseUrl}/lesson/{id}/notes/mine`,
    getCourseFeaturedNote: `${baseUrl}/lesson/{id}/notes/featured`,
    addCourseNote: `${baseUrl}/course-chapter/{id}/notes`,
    getCourseResource: `${baseUrl}/course-chapter/{id}/resource`,
    getCourseResourceByLesson: `${baseUrl}/lesson/{id}/mooc/resource`,
    getKnowledgeList: `${baseUrl}/lesson/{id}/knowledge`,
    getKnowledgeDetail: `${baseUrl}/knowledge/{id}`,
    getRankingList: `${baseUrl}/lesson/{id}/ranking`,
    getMyRanking: `${baseUrl}/lesson/{id}/ranking/mine`,
    getMyCourse: `${baseUrl}/lesson/mine`,
    getMonthLession: `${baseUrl}/course-hour/month`,
    getCourseHours: `${baseUrl}/course-hour`,
    joinCourse: `${baseUrl}/lesson/{id}/join`,
    exitCourse:`${baseUrl}/lesson/{id}/exit`,
    getStatisticsCount:`${baseUrl}/lesson-statistics/count`,
    getStatisticsActivity:`${baseUrl}/lesson-statistics/activity`,
    getStaticticsResource:`${baseUrl}/lesson-statistics/resource`,
    getCourseResourceQuiz:`${baseUrl}/course-resource/quiz/{id}`,
    answerQuestion:`${baseUrl}/course-resource/quiz/{id}/answer`,
};
/**
 * 获取热门课程
 */
export function getHotCourse (data, callback) {
    return http.get(paths.getHotCourse, { data, noLogin: true }, callback)
}
/**
 * 获取课程列表 
 * @param {*} data 
 * @param {*} callback 
 * @returns 
 */
export function getCourse (data, callback) {
    return http.get(paths.getCourse, { data, noLogin: true }, callback);
}
/**
 * 获取课程详情
 * @param {*} id 
 * @param {*} data 
 * @param {*} callback 
 * @returns 
 */
export function getCourseDetail (id, data, callback) {
    var tPath = paths.getCourseDetail.replace('{id}', id);
    return http.get(tPath, { data }, callback)
}
//
export function getCourseChapter (id, data, callback) {
    var tPath = paths.getCourseChapter.replace('{id}', id);
    return http.get(tPath, { data, noLogin: true }, callback)
}
//获取课程目录
export function getLessonChapter (id, data, callback) {
    var tPath = paths.getLessonChapter.replace('{id}', id);
    return http.get(tPath, { data, noLogin: true }, callback)
}

export function getStudentCourseList (data, callback) {
    return http.get(paths.getStudentCourseList, { data }, callback)
}
export function getStudentCourseCollect (data, callback) {
    return http.get(paths.getStudentCourseCollect, { data }, callback)
}

/**
 * 获取课程评价
 */
export function getCourseComment (id, data, callback) {
    var tPath = paths.getCourseComment.replace('{id}', id);
    return http.get(tPath, { data }, callback)
}

/**
 * 点赞评论
 */
export function commentLike (id, data, callback) {
    var tPath = paths.commentLike.replace('{id}', id);
    return http.post(tPath, {
        data, header: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    }, callback)
}

/**
 *取消点赞评论
 */
export function commentCancelLike (id, data, callback) {
    var tPath = paths.commentCancelLike.replace('{id}', id);
    return http.post(tPath, {
        data, header: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    }, callback)
}

/**
 * 课堂活动统计
 * @param {*} data 
 * @param {*} callback 
 * @returns 
 */
export function getLessonStatisticsActivity (data, callback) {
    return http.get(paths.getLessonStatisticsActivity, { data }, callback)
}
/**
 * 课堂活动统计
 * @param {*} data 
 * @param {*} callback 
 * @returns 
 */
export function getCourseHoursResource (id, callback) {
    var tPath = paths.getCourseHoursResource.replace('{id}', id);
    return http.get(tPath, null, callback)
}

/**
 * 课程签到
 * @param {*} data 
 * @param {*} callback 
 * @returns 
 */
export function signInCourseResource (id, callback) {
    var tPath = paths.signInCourseResource.replace('{id}', id);
    return http.post(tPath, null, callback)
}

/**
 * 获取签到结果
 * @param {*} data 
 * @param {*} callback 
 * @returns 
 */
export function getSignInCourseResource (id, callback) {
    var tPath = paths.getSignInCourseResource.replace('{id}', id);
    return http.get(tPath, null, callback)
}


/**
 * 投票
 * @param {*} data 
 * @param {*} callback 
 * @returns 
 */
export function vote (id, data, callback) {
    var tPath = paths.vote.replace('{id}', id);
    return http.post(tPath, { data }, callback)
}
/**
 * 投票详情
 * @param {*} data 
 * @param {*} callback 
 * @returns 
 */
export function getVoteDetail (id, callback) {
    var tPath = paths.getVoteDetail.replace('{id}', id);
    return http.get(tPath, null, callback)
}
/**
 * 投票结果
 * @param {*} data 
 * @param {*} callback 
 * @returns 
 */
export function getVoteResult (id, callback) {
    var tPath = paths.getVoteResult.replace('{id}', id);
    return http.get(tPath, null, callback)
}

/**
 * 取消课程收藏
 * @param {*} data 
 * @param {*} callback 
 * @returns 
 */
export function cancelCourseCollect (id, callback) {
    var tPath = paths.cancelCourseCollect.replace('{id}', id);
    return http.post(tPath, null, callback)
}
/**
 * 获取加入课程状态
 */
export function getJoinStatus (data, callback) {
    return http.get(paths.joinStatus, { data }, callback);
}

/**
 * 收藏课程
 */
export function collectCourse (id, data, callback) {
    var tPath = paths.collectCourse.replace('{id}', id);
    return http.post(tPath, {
        data, header: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    }, callback)
}

/**
 * 取消收藏课程
 */
export function cancelCollectCourse (id, data, callback) {
    var tPath = paths.cancelCollectCourse.replace('{id}', id);
    return http.post(tPath, {
        data, header: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    }, callback)
}
/**
 * 课程评论
 */
export function commentCourse (id, data, callback) {
    var tPath = paths.commentCourse.replace('{id}', id);
    return http.post(tPath, {
        data
    }, callback)
}
/**
 * 获取班级选项
 * @param {*} data 
 * @param {*} callback 
 * @returns 
 */
export function getLessionOption (data, callback) {
    return http.get(paths.getLessionOption, {
        data, noLogin: true
    }, callback)
}
/**
 * 获取资源详情
 */
export function getResourceDetail (id, callback) {
    var tPath = paths.getResourceDetail.replace('{id}', id);
    return http.get(tPath, {}, callback)
}

/**
 * 更新课程活动状态-> 已完成
 */
export function updateCourseActityStatus (id, callback) {
    var tPath = paths.updateCourseActityStatus.replace('{id}', id);
    return http.post(tPath, null, callback)
}

/***
 * 获取我的笔记：课程详情中
 */
export function getCourseMineNote (id, callback) {
    var tPath = paths.getCourseMineNote.replace('{id}', id);
    return http.get(tPath, {}, callback)
}


/***
 * 获取精选笔记：课程详情中
 */
export function getCourseFeaturedNote (id, callback) {
    var tPath = paths.getCourseFeaturedNote.replace('{id}', id);
    return http.get(tPath, {}, callback)
}
/**
 * 添加课程笔记
 * @param {*} id 
 * @param {*} callback 
 * @returns 
 */
export function addCourseNote (id, data, callback) {
    var tPath = paths.addCourseNote.replace('{id}', id);
    return http.post(tPath, { data }, callback)
}

/**
 * 获取课程资源
 */
export function getCourseResource (id, callback) {
    var tPath = paths.getCourseResource.replace('{id}', id);
    return http.get(tPath, {}, callback)
}
/**
 * 获取课程资源-- by lesson
 */
 export function getCourseResourceByLesson (id, callback) {
    var tPath = paths.getCourseResourceByLesson.replace('{id}', id);
    return http.get(tPath, {}, callback)
}
/**
 * 获取知识库列表
 * id:课程id
 */
export function getKnowledgeList (id, data, callback) {
    var tPath = paths.getKnowledgeList.replace('{id}', id);
    return http.get(tPath, { data }, callback)
}
/**
 * 获取知识点详情
 * @param {*} id 
 * @param {*} callback 
 * @returns 
 */
export function getKnowledgeDetail (id, callback) {
    var tPath = paths.getKnowledgeDetail.replace('{id}', id);
    return http.get(tPath, {}, callback)
}

/**
 * 获取排行榜
 * @param {课程id} id 
 * @param {*} data 
 * @param {*} callback 
 * @returns 
 */
export function getRankingList (id, data, callback) {
    var tPath = paths.getRankingList.replace('{id}', id);
    return http.get(tPath, { data }, callback)
}
/**
 * 获取我的排行
 * @param {课程id} id 
 * @param {*} callback 
 */
export function getMyRanking (id, callback) {
    var tPath = paths.getMyRanking.replace('{id}', id);
    return http.get(tPath, {}, callback)
}
/**
 * 获取我的课程
 * @param {*} data 
 * @param {*} callback 
 */
export function getMyCourse (data, callback) {
    return http.get(paths.getMyCourse, { data }, callback)
}

/**
 * 获取月份的课时
 * @param {*} data 
 * @param {*} callback 
 * @returns 
 */
export function getMonthLession (data, callback) {
    return http.get(paths.getMonthLession, { data }, callback)
}

/**
 * 查看课时
 * @param {*} data 
 * @param {*} callback 
 * @returns 
 */
export function getCourseHours (data, callback) {
    return http.get(paths.getCourseHours, { data }, callback)
}

/**
 * 加入课程
 */
export function joinCourse (id, callback) {
    var tPath = paths.joinCourse.replace('{id}', id);
    return http.post(tPath, { header: { 'Content-Type': 'application/x-www-form-urlencoded' } }, callback)
}

/**退出课程 */
export function exitCourse(id,callback){
      var tPath = paths.exitCourse.replace('{id}', id);
    return http.post(tPath, { header: { 'Content-Type': 'application/x-www-form-urlencoded' } }, callback)
    
}

/**
 * 获取统计数量
 */
export function getStatisticsCount(data,callback){
   return http.get(paths.getStatisticsCount, { data }, callback) 
}
/**
 * 获取活动统计
 */
export function getStatisticsActivity(data,callback){
   return http.get(paths.getStatisticsActivity, { data }, callback) 
}
/**
 * 获取资源统计
 */
export function getStaticticsResource(data,callback){
   return http.get(paths.getStaticticsResource, { data }, callback) 
}

/**
 * 获取提问详情
 * @param {课程id} id 
 * @param {*} callback 
 * @returns 
 */
 export function getCourseResourceQuiz (id,callback) {
    var tPath = paths.getCourseResourceQuiz.replace('{id}', id);
    return http.get(tPath, {}, callback)
}

/**
 * 提问抢答
 * @param {课程id} id 
 * @param {*} callback 
 * @returns 
 */
 export function answerQuestion (id,callback) {
    var tPath = paths.answerQuestion.replace('{id}', id);
    return http.post(tPath, {}, callback)
}